package com.clkj.xiuzheng.dao;

import com.clkj.xiuzheng.pojo.Shop;
import com.clkj.xiuzheng.pojo.UserPut;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author yawang
 * @create 2024/04/12 13:53:44
 **/
@Repository
public interface UserPutMapper extends Mapper<UserPut> {
    @Select("select count(*) from t_cl_customerVisit  where user_id = #{userId} and DateDiff(day,visit_date,getDate())<=1")
    Integer getTodayVisit(Integer userId);
    @Select("select count(*) from t_cl_customerVisit  where user_id = #{userId} and DateDiff(day,visit_date,getDate())<=30")
    Integer getMonthVisit(Integer userId);
    @Select("SELECT  p.*, u1.user_name AS user_name,  u1.user_tel AS user_tel, u2.user_name AS promoter_name FROM   t_cl_userPut p  LEFT JOIN  t_cl_user u1 ON p.user_id = u1.user_id LEFT JOIN  t_cl_user u2 ON p.promoter_id = u2.user_id;")
    List<UserPut> getAllSaleUserOrder();
    @Select("SELECT  p.*,  u1.user_name AS user_name, u1.user_tel AS user_tel, u2.user_name AS promoter_name FROM  t_cl_userPut p  LEFT JOIN  t_cl_user u1 ON p.user_id = u1.user_id LEFT JOIN  t_cl_user u2 ON p.promoter_id = u2.user_id WHERE  p.promoter_id = #{promoterId};")
    List<UserPut> getSaleUserOrder(@Param("promoterId") Integer promoterId);
    @Insert("INSERT INTO t_cl_area (area_id,user_id,is_deleted) values (#{areaId},#{userId},1)")
    void addpromoterArea(@Param("areaId") Integer areaId, @Param("userId") Integer userId);



    @Insert("insert into t_cl_userPut values (#{userId},#{putMoney},#{putDate},#{putAdv},#{isPut}," +
            "#{shopId},#{startTime},#{endTime},#{shopTotal},#{promoterId},#{isContact}," +
            "#{receiptContent},#{payMoney},#{payStatus},#{payDate})")
    @Options(useGeneratedKeys = true, keyProperty = "recordId", keyColumn = "record_id")
    void addUserPut(UserPut userPut);

    @Select("select * from t_cl_userPut  where is_put = 1 ")
    List<UserPut> listHcustomer();
    @Select({"<script>",
            "select * from t_cl_userPut",
            "where 1=1",
            "<if test ='isPut != null'>",
            "and is_put = #{isPut}",
            "</if>",
            "</script>"})
    List<UserPut> getPutList(@Param("isPut") Integer isPut);
}
